package com.project.livetv.activity;


import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidadvance.topsnackbar.TSnackbar;
import com.project.livetv.R;
import com.project.livetv.fragment.MainFragment;
import com.project.livetv.fragment.PeopleFragment;

public class MainActivity extends BaseActivity {
    private FrameLayout frameLayout;
    private RadioButton live_radiobtn, room_radiobtn, me_radiobtn;
    private FragmentManager manager;
    private FragmentTransaction transaction;
    private long time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       // startActivity(new Intent(this,MessageActivity.class));

    }

    @Override
    public void initView() {
        frameLayout = (FrameLayout) findViewById(R.id.main_live_framelayout);
        live_radiobtn = (RadioButton) findViewById(R.id.live_btn);
        room_radiobtn = (RadioButton) findViewById(R.id.room_btn);
        me_radiobtn = (RadioButton) findViewById(R.id.me_btn);
    }

    @Override
    public void initData() {
        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
        transaction.add(R.id.main_live_framelayout, MainFragment.newInstance("我是主页面"));
        transaction.commit();
    }

    @Override
    public void setData() {

    }

    @Override
    public void setListener() {

    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.live_btn:
                getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.main_live_framelayout, MainFragment.newInstance("我是主页面")).commit();


                break;
            case R.id.room_btn:
                startActivity(new Intent(this,SopcastActivity.class));
                break;
            case R.id.me_btn:
                getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.main_live_framelayout, PeopleFragment.newInstance("dddd")).commit();
                break;
        }
    }


    //返回


    @Override
    public void onBackPressed() {
        if(System.currentTimeMillis()-time<1000){
            android.os.Process.killProcess(android.os.Process.myPid());
        }else{
            TSnackbar tSnackbar = TSnackbar.make(findViewById(android.R.id.content), "再按一次返回桌面", TSnackbar.LENGTH_SHORT);
            View view = tSnackbar.getView();
            view.setBackgroundColor(Color.parseColor("#A58DE3"));
            TextView textView = (TextView) view.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
            textView.setTextSize(15);
            textView.setGravity(RelativeLayout.CENTER_HORIZONTAL);
            tSnackbar.show();
        }
        time = System.currentTimeMillis();

    }


}